package top.kaoshanji.q1ch02a;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

/**
 * 代码清单-q1ch02a-23页a：加载配置文件并调用Bean
 * @author kaoshanji
 * ^_^
 * create time 2025/5/27 19:02
 */
public class Application {

    private BeanFactory beanFactory;

    public Application() {
        beanFactory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader((DefaultListableBeanFactory)beanFactory);
        reader.loadBeanDefinitions("q1ch02a/beans.xml");
    }

    public void sayHello() {
        Hello hello = beanFactory.getBean("hello", Hello.class);
        System.out.println(hello.hello());
    }

    public static void main(String[] args) {
        Application application = new Application();
        application.sayHello();
    }

}
